<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<c:set var="ctx" value="${pageContext.request.contextPath }" />
<link rel="stylesheet"
	href="${ctx }/resources/js/select2/select2.min.css" />
<script type="text/javascript"
	src="${ctx }/resources/js/select2/select2.min.js"></script>
<script type="text/javascript"
	src="${ctx }/resources/js/select2/zh-CN.js"></script>
 
 
<%-- <script src="${basePath}/script/ajaxfileupload.js" type="text/javascript"></script>
  --%>

 <script src="${ctx }/resources/js/upload/ajaxfileupload.js"    type="text/javascript">  
	</script>
<script type="text/javascript">

function doSaveCover() {
    var fileName = $("#cover").val();
    var type = fileName.split(".");
    var ftype = type[type.length - 1]; //获取文件后缀
    $.ajaxFileUpload({
        url: '${ctx }/files/upload/' + ftype,
        secureuri: false, //是否需要安全协议，一般设置为false
        fileElementId: ['cover'], //文件上传域的ID
        dataType: 'json', //返回值类型 一般设置为json
        success: function (data, status) //服务器成功响应处理函数
        {
        	alert(data);
            if (data.result == 0) {
            	var fileId = data.data[0].id;
            	var filePath = '/files/view/jpg/' + fileId;
            	$("#hiddenCover").val(filePath);
            	 alert(filePath);
            }
        },
        error: function (data, status, e) //服务器响应失败处理函数
        {
            alert(e);
        }
    });
}

function doSavePoster() {
    var fileName = $("#poster").val();
    var type = fileName.split(".");
    var ftype = type[type.length - 1]; //获取文件后缀
    $.ajaxFileUpload({
        url: '${ctx }/files/upload/' + ftype,
        secureuri: false, //是否需要安全协议，一般设置为false
        fileElementId: ['poster'], //文件上传域的ID
        dataType: 'json', //返回值类型 一般设置为json
        success: function (data, status) //服务器成功响应处理函数
        {
        	alert(data);
            if (data.result == 0) {
            	var fileId = data.data[0].id;
            	var filePath = '/files/view/jpg/' + fileId;
            	$("#hiddenPoster").val(filePath);
            }
        },
        error: function (data, status, e) //服务器响应失败处理函数
        {
            alert(e);
        }
    });
}
function logoUploadComplete(path) {
	$('#LogoPath').val(path);
	var Img = document.createElement("img");
	Img.src = path;
	document.getElementById("ChooseLogo").innerHTML = Img.outerHTML;
};

/*二级联动  */
$(function() { 
	$("#channel").change(function() {
	  $("#two option[value!='']").remove();
	 /*  $.post("series/getAllcode.html?code=" + $("#channel").val(),  
		        function(data, textStatus) {
		        	var dataObj = eval("(" + data + ")");  
		            for (var i = 0; i < dataObj.length; i++) {  
		                var $option = $("<option></option>");  
		                $option.attr("value", dataObj[i].id);  
		                $option.text(dataObj[i].name);  
		                $("#two").append($option);  
		            }  
		        }); */
        $.post("series/getDramaTypes.html?code=" + $("#channel").val(),  
        function(data, textStatus) {
        	var dataObj = eval("(" + data + ")");  
            for (var i = 0; i < dataObj.length; i++) {  
                var $option = $("<option></option>");  
                $option.attr("value", dataObj[i].id);  
                $option.text(dataObj[i].name);  
                $("#two").append($option);  
            }  
        });
        $.post("series/getSerieKinds.html?code=" + $("#two").val(),  
           function(data, textStatus) {
           	var dataObj = eval("(" + data + ")");  
               for (var i = 0; i < dataObj.length; i++) {  
                   var $option = $("<option></option>");  
                   $option.attr("value", dataObj[i].id);  
                   $option.text(dataObj[i].name);  
                   $("#two").append($option);  
               }  
        });  
        
    });  
});
</script>
<div class="page-header">
	<h1>
		<c:if test="${empty seriesEntity}">
		新增视频
		</c:if>
		<c:if test="${!empty seriesEntity}">
		编辑视频
		</c:if>
	</h1>
</div>
<div class="row" style="margin-top:5px;">
	<div class="col-xs-12">
	<form action="series/addinsert.html" id="addUI" name="addUI" class="form-horizontal" role="form" method="post">
	 
		<c:if test="${!empty seriesEntity}">
			<input type="hidden" id="pageNum" name="pageNum" value="${page.pageNum }">
			<input type="hidden" id="pageSize" name="pageSize" value="${page.pageSize }">
			<input type="hidden" id="orderByColumn" name="orderByColumn" value="${page.orderByColumn }">
			<input type="hidden" id="orderByType" name="orderByType" value="${page.orderByType }">
			<input type="hidden" name="id" id="seriesId" value="${seriesEntity.id }">
			<input type="hidden" name="series.id" value="${seriesEntity.id }">
		</c:if>
		   <div class="form-group">
		      <label class="control-label col-sm-1 no-padding-right" for="name">剧集名称</label>
		      <div class="col-sm-10">
		      <div class="clearfix">
		       <input class="form-control" name="name" id="name" type="text"  placeholder="剧集名称"/>
		      </div>
		      </div>
		   </div>
			<div class="form-group">
			      <label class="control-label col-sm-1 no-padding-right" for="description">描述</label>
			      <div class="col-sm-10">
			      <div class="clearfix">
			         <input class="form-control" name="description" id="description" type="text" value="${seriesEntity.description }"
			         placeholder="描述"/>
		      	</div>
		      	</div>
		    </div>   
		    <div class="form-group">
			      <label class="control-label col-sm-1 no-padding-right" for="summary">简介</label>
			      <div class="col-sm-10">
			      <div class="clearfix">
			         <input class="form-control" name="summary" id="summary" type="text" placeholder="简介"/>
		      	</div>
		      	</div>
		    </div>
		   <div class="form-group">
		      <label class="control-label col-sm-1 no-padding-right" for="channel">频道</label>
		      <div class="col-sm-10">
		      <div class="clearfix"> 
		        <select id="channel" class="form-control" name='channel'> 
		    			 <c:forEach items="${list_channel}" var="t" > 	 
		    				<option value="${t.code}">${t.name}</option>
		    				</c:forEach>
	    		</select >
		      </div>
		      </div>
		   </div>   
		   <div class="form-group">
		      <label class="control-label col-sm-1 no-padding-right" for="type">剧情类型</label>
		      <div class="col-sm-10">
		      <div class="clearfix">
		    <select id="two" class="form-control" name='type'>
		               <option value="">-请选择-</option> 
	    				 </select> 
		      </div>
		      </div>
		   </div>
		   <div class="form-group">
		      <label class="control-label col-sm-1 no-padding-right" for="type">频道的分类</label>
		      <div class="col-sm-10">
		      <div class="clearfix">
		     <select id="three" class="form-control" name='kind'>
		    		<c:forEach items="${list_chan}" var="t" > 	 
		    				<option value="${t.code}">${t.name}</option>
		    				</c:forEach>
	    				 </select> 	     
		      </div>
		      </div>
		   </div>
		   
		   <div class="form-group">
		      <label class="control-label col-sm-1 no-padding-right" for="tag">标签</label>
		      <div class="col-sm-10">
		      <div class="clearfix">
		         <input class="form-control" name="tag" id="tag" type="text"
		         value="${seriesEntity.tag }" placeholder="标签"/>
		      </div>
		      </div>
		   </div>
		   
		   <div class="form-group">
		      <label class="control-label col-sm-1 no-padding-right" for="language">语言</label>
		      <div class="col-sm-10">
		      <div class="clearfix">
		         <input class="form-control" name="language" id="language" type="text"
		         value="${seriesEntity.language }" placeholder="语言"/>
		      </div>
		      </div>
		   </div>
		   
		   <div class="form-group">
		      <label class="control-label col-sm-1 no-padding-right" for="year">年份</label>
		      <div class="col-sm-10">
		      <div class="clearfix">
		         <input class="form-control" name="year" id="year" type="text"
		         value="${seriesEntity.year }" placeholder="语言"/>
		      </div>
		      </div>
		   </div>
		   
		   <div class="form-group">
		      <label class="control-label col-sm-1 no-padding-right" for="area">地区</label>
		      <div class="col-sm-10">
		      <div class="clearfix">
		         <input class="form-control" name="area" id="area" type="text"
		         value="${seriesEntity.area }" placeholder="地区"/>
		      </div>
		      </div>
		   </div>
		   <div class="form-group">
		      <label class="control-label col-sm-1 no-padding-right" for="poster">海报</label>
		      <div class="col-sm-10">
		      <div class="clearfix">
		        
		         <input class="form-control" name="files" id="poster" type="file"
		         value="${seriesEntity.poster }" placeholder="海报"/><input type="button" onclick="javascript:doSavePoster();" value="上传" class="btn btn-primary btn-sm"/>
		       <input type="hidden" id="hiddenPoster" name="poster" >
		      </div>
		      </div>
		   </div>
		  
		   <div class="form-group">
		      <label class="control-label col-sm-1 no-padding-right" for="cover" >封面</label>
		      <div class="col-sm-10">
		      <div class="clearfix">
		       
		         <input class="form-control" name="files" id="cover" type="file"  
		         value="${seriesEntity.cover }" placeholder="封面"/><input type="button"  onclick="javascript:doSaveCover();" value="上传" class="btn btn-primary btn-sm"/> 
		         <input type="hidden" id="hiddenCover" name="cover" >
		      </div>
		      </div>
		   </div>
		   
		   <div class="form-group">
		      <label class="control-label col-sm-1 no-padding-right" for="director">导演</label>
		      <div class="col-sm-10">
		      <div class="clearfix">
		         <input class="form-control" name="director" id="director" type="text"
		         value="${seriesEntity.director }" placeholder="导演"/>
		      </div>
		      </div>
		   </div>
		   
		   <div class="form-group">
		      <label class="control-label col-sm-1 no-padding-right" for="actor">主演</label>
		      <div class="col-sm-10">
		      <div class="clearfix">
		         <input class="form-control" name="actor" id="actor" type="text"
		         value="${seriesEntity.actor }" placeholder="主演"/>
		      </div>
		      </div>
		   </div>
		   
		   <div class="form-group">
		      <label class="control-label col-sm-1 no-padding-right" for="setSum">总集数</label>
		      <div class="col-sm-10">
		      <div class="clearfix">
		         <input class="form-control" name="setSum" id="setSum" type="text"
		         value="${seriesEntity.setSum }" placeholder="总集数"/>
		      </div>
		      </div>
		   </div>  
		</form>
		<div class="hr hr-dotted"></div>
	</div>
</div>
<div class="center">
	<button id="btnAdd" type="button" onclick="javascript:$('#addUI').submit();" class="btn btn-success btn-sm">
	  	<i class="fa fa-user-plus"></i>&nbsp;
	  	<c:if test="${empty seriesEntity}">
		添加
		</c:if>
	  	<c:if test="${!empty seriesEntity}">
		保存
		</c:if>
	</button>
		<button id="btn" type="button" onclick="webside.common.loadPage('/series/listUI.html<c:if test="${!empty seriesEntity}">?page=${page.pageNum }&rows=${page.pageSize }&sidx=${page.orderByColumn }&sord=${page.orderByType }</c:if>')" class="btn btn-info btn-sm">
		<i class="fa fa-undo"></i>&nbsp;返回
	</button>
</div>